package com.heima.admin.controller.v1;
import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ChannelDTO;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags = "频道管理",description = "频道管理Api")
public class AdChannelController {
    @Autowired
    private AdChannelService channelService;

    /**
     * 根据名称分页查询频道列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDTO dto) {
        return channelService.findByNameAndPage(dto);
    }

    @GetMapping("/channels")
    @ApiOperation("获取全部频道列表")
    public ResponseResult findAll(){
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }

    /**
     * 新增频道
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("频道新增")
    public ResponseResult insert(@RequestBody AdChannel adChannel){
        return channelService.insert(adChannel);
    }

    @PostMapping("/update")
    @ApiOperation("频道修改,频道有效无效设置")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return channelService.update(adChannel);
    }

    @GetMapping("/del/{id}")
    @ApiOperation("根据id删除频道")
    public ResponseResult deleteById(@PathVariable Integer id){
        return channelService.deleteById(id);
    }

    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {
        return ResponseResult.okResult(channelService.getById(id));
    }


}